<?php
namespace app\admin\controller;
use app\admin\common\Base;
use think\Db;
 //保修条款
class Cardreport extends Base
{

     //保修条款1-1
    public function index()
    {
    	$info=Db::name('card_record')->order('id desc')->find();
    	$this->assign('info',$info);
        return $this->fetch();
    }

 
    //保修条款1-2
    public function report_save()
    {
        $status=0;
        $msg="操作失败";
        $data = $this->request->param();
        $post=$data;
        unset($data['type']);
        unset($data['pid']);
        // 启动事务
        Db::startTrans();
        //先添加记录
        $data['updatetime']=time();
        $data['addtime']=time();
        $data['time']=time();
        $data['nickname']=date('Y-m-d',time());
        $pid=Db::name('card_record')->insertGetId($data);
        $type=$post['type'];//1.不影响之前;2.同步更新全部
        if($type==2){//同步更新全部
            $res=Db::name('card')->where('checkstatus','neq',0)->setField('pid',$pid);
            if($res){
                // 提交事务
                Db::commit();
                adminlog('修改保修条款','修改');
                $status=1;
                $msg="修改成功";
                return ['status'=>$status, 'msg'=> $msg];
            }else{
                // 回滚事务
                 Db::rollback();

            }
             

        }else{//不做任何处理
            // 提交事务
            Db::commit();
            adminlog('修改保修条款','修改');
            $status=1;
            $msg="修改成功";

        }

       
        return ['status'=>$status, 'msg'=> $msg];
    }



}
